using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace SampleWebParts
{
  public class ListViewer : WebPart
  {
    private string listName = "Links";
    [WebBrowsable(true), Personalizable(PersonalizationScope.Shared)]
    [WebDescription("Name of list containing items")]
    public string ListName
    {
      get { return listName; }
      set { listName = value; }
    }

    private string fieldName = "Title";
    [WebBrowsable(true), Personalizable(PersonalizationScope.Shared)]
    [WebDescription("Name of field to use as text in list")]
    public string FieldName
    {
      get { return fieldName; }
      set { fieldName = value; }
    }

    protected override void CreateChildControls()
    {
      SPWeb site = SPContext.Current.Web;

      LiteralControl heading = new LiteralControl("<h2>HTML Heading</h2>\r\n");
      Controls.Add(heading);
      Controls.Add(new LiteralControl("<ul>\r\n"));

      SPList list = site.Lists[ListName];
      foreach (SPListItem item in list.Items)
        Controls.Add(new LiteralControl("  <li>" + item[FieldName].ToString() + "</li>\r\n"));
      Controls.Add(new LiteralControl("</ul>\r\n"));
      base.CreateChildControls();
    }
  }
}
